#include"Shm.hpp"
#include"name_pipe.hpp"

int main()
{
    //获取key值
    key_t key = GetShmKeyorDie();
    cout << "key: " << ToHex(key) << endl;

    //1.获取共享内存
    int shmid = GetShm(key);
    cout << "shmid: " << shmid << endl;

    //2.进程连接到共享内存,构建映射
    char* addr = (char*)AttShm(shmid);

    //3.进程间通信 
    Sysn sn;
    sn.OpenWriteorDie(); //以只写的方式打开管道
    memset(addr, '0', 1);
    for(char ch = 'A'; ch < 'Z'; ch++)
    {
        addr[ch - 'A'] = ch;
        sleep(1);
        sn.Wakeup(); //写入完成,唤醒服务端
    }

    //4.断开共享内存的连接,解除映射
    DetachShm(addr);

    //5.删除共享内存
    DelShm(shmid);

    return 0;
}